import Vue from 'vue'
import Vuex from 'vuex'
import { COUNTADD } from './type';

Vue.use(Vuex)

//每一个Vuex应用的核心就是store(仓库)
// 1.Vuex的状态储存是响应式的
// 2.你不能直接改变store的状态 唯一途径就是mutations
export default new Vuex.Store({
  state: {
    count:1000,
    city:"美丽武汉",
    msg:"Are you ok?",
    text:"Work hard for offer",
    data:{
      flag:true,
      word:"2116-daydayup"
    }
  },
  getters: {
    newCount(state){
      return state.count * 10 + 888
    },
    text2(state){
      return state.text.split('').reverse.join('')
    }
  },

  mutations: {
    countAdd(state){
      state.count++;
    },
    changeCity(state,city){
      state.city=city;
    },
    changeMsg(state,payload){
      state.msg=payload;
    },
    changeText(state,payload){
      state.text=payload;
    },
    changeCount(state,payload){
      state.count+=payload;
    },
    changeFlag(state,payload){
      state.data = {
        ...state.data,
        flag:payload
      }
    },
    changeWord(state,payload){
      state.data={
        ...state.data,
        word:payload
      }
    }
  },
  actions: {
  },
  modules: {
  }
})
